package xiaocao.learn.java.io.nio;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel.MapMode;

/**
 * 大文件的内存映射可以极大的加快文件读写速度
 * @author Administrator
 *
 */
public class LargeMappedFilesDemo {
	
	static int length = 0x8FFFFFF;
	
	public static void main(String[] args) throws Exception {
		MappedByteBuffer out = new RandomAccessFile("d://test.data", "rw").getChannel().map(MapMode.READ_WRITE, 0, length);
		for(int i = 0; i < length; i++) {
			out.put((byte)'x');
		}
		for(int i = length / 2; i < length /2 + 6; i++) {
			System.out.println((char)out.get(i));
		}
	}

}
